package com.auoem.radio.base;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.auoem.radio.R;
import com.auctus.am.framework.enums.ApiStatusEnum;
import com.auoem.radio.common.custview.ProgressUtil;
import com.auoem.radio.common.utils.ToastUtils;

@SuppressLint("Registered")
public class BaseActivity extends AppCompatActivity {

    private ProgressUtil mProgressUtil;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setStatusBarMode();
    }

    protected boolean lightStatusBar() {
        return false;
    }

    private void setStatusBarMode() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View decor = getWindow().getDecorView();
        if (lightStatusBar()) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }
            getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimary));
        } else {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    public void showProgress(final String message) {
        if (mProgressUtil == null) {
            mProgressUtil = new ProgressUtil(this);
        }
        mProgressUtil.showProgressDialog(message);
    }

    public void showProgress(final int message) {
        if (mProgressUtil == null) {
            mProgressUtil = new ProgressUtil(this);
        }
        mProgressUtil.showProgressDialog(this.getResources().getString(message));
    }

    public void cancelProgress() {
        if (mProgressUtil != null) {
            mProgressUtil.cancelProgressDialog();
        }
    }

    public void toastResultUI(final ApiStatusEnum status) {
         runOnUiThread(new Runnable() {
            @Override
            public void run() {
                cancelProgress();
                if (status == ApiStatusEnum.SUCCESS) {
                    ToastUtils.showShortToast(BaseActivity.this, R.string.am_common_exe_success);
                } else {
                    ToastUtils.showShortToast(BaseActivity.this, R.string.am_common_exe_failure);
                }
            }
        });
    }

    public void toastResultUI(final String msg) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                cancelProgress();
                ToastUtils.showShortToast(BaseActivity.this, msg);
            }
        });
    }

    public void toastResultUI(final int iMsg) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                cancelProgress();
                ToastUtils.showShortToast(BaseActivity.this, iMsg);
            }
        });
    }
}